package tools

import (
	"errors"
	"sync"
)

var lock sync.Mutex
var projectLocker sync.Map

type UnLocker struct {
	projectId interface{}
}

func (unLocker *UnLocker) Unlock() {
	projectLocker.Delete(unLocker.projectId)
}
func GetProjectLocker(projectId interface{}) (UnLocker, error) {
	lock.Lock()
	defer lock.Unlock()
	_, ok := projectLocker.Load(projectId)
	if !ok {
		return UnLocker{projectId: projectId}, nil
	} else {
		return UnLocker{}, errors.New("获取锁失败")
	}
}
